//
//  BundleUtil.m
//  SWIOSLibary
//
//  Created by shaowei on 13-7-19.
//  Copyright (c) 2013年 LianZhan. All rights reserved.
//

#import "SWBundleUtil.h"

@implementation SWBundleUtil

+ (id)shareInstance{
    static NSBundle *instance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        instance = [NSBundle bundleWithURL:[[NSBundle mainBundle] URLForResource:@"SWIOSLibResource"
                                                                   withExtension:@"bundle"]];
    });
    return instance;
}

+ (NSString *)pathForResource:(NSString *)resName ofType:(BundleResourceType)type{
//    NSString *resPath = [[NSBundle mainBundle] resourcePath];
//    NSString *bundlePath = [resPath stringByAppendingPathComponent:@"SWIOSLibary.bundle"];
//    NSString *typePath = nil;
//    
//    switch (type) {
//        case BundleResourceOfImage:{
//            typePath =@"images";
//        }
//            break;
//        case BundleResourceOfFile:{
//            typePath =@"files";
//        }
//            break;
//        case BundleResourceOfMedia:{
//            typePath =@"media";
//        }
//            break;
//            
//        default:
//            SWASSERT_SWITCH_OVER;
//            break;
//    }
//    
//    NSString *resultPath = [[bundlePath stringByAppendingPathComponent:typePath]
//                            stringByAppendingPathComponent:resName];
//    
//    if (![[NSFileManager defaultManager] fileExistsAtPath:resultPath]) {
//        //文件不存在
//        resultPath = nil;
//    }
    
    NSString *resultPath = [[SWBundleUtil shareInstance] pathForResource:resName ofType:nil];
    
    return resultPath;
    
}

@end
